package com.woniu83.singleton;/**
 * @author author
 * @create 2021-11-10 8:09
 */

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * author: SuTing  <br/>
 * Date: 2021/11/10:8:09  <br/>
 * Description:
 */
public class Factory {
    static Map<String,Person> map=new HashMap<>();
    static{

        InputStream stream = Factory.class.getResourceAsStream("CreatePerson.properties");
        Properties p = new Properties();

        try {
            p.load(stream);
            Set<Object> keys = p.keySet();
            for(Object key:keys){
                Person person= (Person) Class.forName(p.getProperty((String) key)).newInstance();
                map.put((String)key,person);
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    public static Person getBean(String name){
        if(map.containsKey(name)){
            return map.get(name);
        } else {
            return null;
        }
    }
}
